package web.servlet.api;

import domain.LyyBaseServlet;
import domain.response.CommandResponse;
import utils.LyyLogUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/commandExecutor")
public class CommandExecutorServlet extends LyyBaseServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String command = request.getParameter("command");
        CommandExecutor.CommandResult result = CommandExecutor.executeCommand(command);
        LyyLogUtil.logD(result.toString());
        CommandResponse commandResponse = new CommandResponse();
        commandResponse.setCommandResult(result);
        jsonResponse(response, commandResponse);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
